package com.foreknow.service.impl;

import com.foreknow.bean.Emp;
import com.foreknow.dao.EmpDAO;
import com.foreknow.dao.impl.EmpDAOImpl;
import com.foreknow.service.EmpService;

import java.sql.SQLException;

public class EmpServiceImpl implements EmpService {
    private EmpDAO dao;

    public void setDao(EmpDAO dao) {
        this.dao = dao;
    }

    @Override
    public boolean add(Emp emp) {
        boolean isRight = false;
        try {
            isRight = dao.save(emp);
            //提交事物commit
        } catch (SQLException e) {
            //回滚（取消之前的所有对数据库的操作
            e.printStackTrace();
        }
        return isRight;
    }

    public static void main(String[] args) {
        EmpServiceImpl service = new EmpServiceImpl();
        EmpDAOImpl dao = new EmpDAOImpl();
        service.setDao(dao);
        service.add(new Emp());
    }
}
